from flask import Flask, request, jsonify
import hashlib
import SparkApi
from urllib.parse import unquote
app = Flask(__name__)

def hua(content):
    return str(SparkApi.HuaChat(content))

@app.route('/manage/ai', methods=['POST'])
def ai_route():
    if 'token' not in request.form or 'content' not in request.form:
        return jsonify({"error": "缺少 token 字段"}), 400
    
    token = request.form['token']
    content=unquote(request.form['content'])
    print(content)
    sha256_token = hashlib.sha256(token.encode('utf-8')).hexdigest()

    if sha256_token == "bcb15f821479b4d5772bd0ca866c00ad5f926e3580720659cc80d39c9d09802a":  # 请将 "特定字符" 替换为实际的加密字符串
        return jsonify({"result": hua(content)})
    else:
        return jsonify({"error": "验证失败"}), 401

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=6767, debug=True)
